package bookstore.repository;

import bookstore.bound.order.StatItem;
import bookstore.model.OrderItem;
import bookstore.model.OrderItemPK;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderItemRepository extends CrudRepository<OrderItem, OrderItemPK> {

    @Query("SELECT new bookstore.bound.order.StatItem(o.orderItemPK.book.isbn, o.orderItemPK.book.name, SUM(o.count), SUM(o.count*o.price)) FROM OrderItem o GROUP BY o.orderItemPK.book.isbn")
    List<StatItem> OrderSaleStat();
}
